import { ref } from 'vue'

export function useHomeLocationPicker() {
	const pickerRef = ref<any>(null)
	const selectedCity = ref('成都')
	const columns = ref(['北京', '上海', '广州', '深圳', '成都', '重庆'])
	const show = ref(false)

	const open = () => {
		let pickerIndex = 0

		if (selectedCity.value) {
			pickerIndex = columns.value.indexOf(selectedCity.value)
		}

		pickerRef.value.setIndexs([pickerIndex])

		show.value = true
	}

	const close = () => {
		show.value = false
	}

	const onConfirm = (e: any) => {
		const val = e.value[0]

		selectedCity.value = val

		close()
	}

	return {
		pickerRef,
		selectedCity,
		columns,
		show,
		open,
		close,
		onConfirm,
	}
}
